﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ZSZ.Core.Entities;

namespace ZSZ.EntityFramework.ModelConfig
{
    class RoleConfig: EntityTypeConfiguration<RoleEntity>
    {
        //public RoleConfig()
        //{
        //    ToTable("T_Roles");
        //    HasMany(r => r.Permissions).WithMany(p => p.Roles).Map(m=>m.ToTable("T_RolePermissions")
        //        .MapLeftKey("RoleId").MapRightKey("PermissionId"));
        //    Property(p => p.Name).IsRequired().HasMaxLength(50);
        //}

        public override void Map(EntityTypeBuilder<RoleEntity> builder)
        {
            builder.ToTable("T_Roles");
            builder.HasMany(e => e.AdminUserRoles).WithOne(u => u.Role).HasForeignKey(f => f.RoleId)
                .OnDelete(DeleteBehavior.ClientSetNull);
            builder.Property(p => p.Name).IsRequired().HasMaxLength(50);
        }
    }
}
